/* eslint-disable no-unused-vars */
module.exports = {
  configureWebpack: {
    devServer: {
      port: 8888, //端口号
      open: true, //自动打开浏览器

      //Mock数据
      before(app) {
        // app.get('请求地址',(req,res) =>{
        //   res.json({

        //   })
        // })
        //用户信息池
        let userpool = [
          { username: "xdn", password: 123456 },
          { username: "lnn", password: 123456 }
        ];
        //登录接口
        let tokenkey = "xdclass";
        app.get("/api/Sign", (req, res) => {
          const { username, password } = req.query;
          if (
            (username == "xdn" && password == 123456) ||
            (username == "lnn" && password == 123456)
          ) {
            res.json({
              code: 200,
              message: "登录成功",
              token:
                tokenkey +
                "-" +
                username +
                "-" +
                (new Date().getTime() + 60 * 60 * 1000)
            });
          } else {
            res.json({
              code: 400,
              message: "用户名或密码错误"
            });
          }
        });
        //首页左侧菜单栏列表接口
        app.get("/api/HomeMenu", (req, res) => {
          res.json({
            menu: [
              {
                title: "用户管理",
                id: 1,
                children: [{ title: "用户列表", id: 11, path: "user" }]
              },
              {
                title: "权限管理",
                id: 2,
                children: [
                  { title: "权限二级菜单", id: 22, path: "jurisdiction1" },
                  { title: "权限二级菜单", id: 222, path: "jurisdiction2" }
                ]
              },
              {
                title: "商品管理",
                id: 3,
                children: [
                  { title: "商品二级菜单", id: 33, path: "commodity1" },
                  { title: "商品二级菜单", id: 333, path: "commodity2" }
                ]
              },
              {
                title: "订单管理",
                id: 4,
                children: [
                  { title: "订单二级菜单", id: 44, path: "order1" },
                  { title: "订单二级菜单", id: 444, path: "order2" }
                ]
              },
              {
                title: "数据统计",
                id: 5,
                children: [
                  { title: "数据二级菜单", id: 55, path: "statistics1" },
                  { title: "数据二级菜单", id: 555, path: "statistics2" }
                ]
              }
            ]
          });
        });
        //用户列表接口
        app.get("/api/User", (req, res) => {
          const { pagesize, pagenum } = req.query;
          switch (pagesize) {
            case "1":
              res.json({
                userlist: [
                  {
                    id: 1,
                    username: "超级大帅哥",
                    type: 1,
                    mobile: "15655117358",
                    email: "243651464@@qq.com",
                    create_time: "2019-11-30",
                    ma_state: true,
                    role_name: "超级管理员"
                  }
                ],
                total: 2
              });
              break;
            // eslint-disable-next-line no-duplicate-case
            case "2":
              res.json({
                userlist: [
                  {
                    id: 1,
                    username: "我是打工仔啦",
                    type: 1,
                    mobile: "15655117358",
                    email: "243651464@@qq.com",
                    create_time: "2019-11-30",
                    ma_state: true,
                    role_name: "打工仔"
                  },
                  {
                    id: 1,
                    username: "打工仔",
                    type: 1,
                    mobile: "15655117358",
                    email: "243651464@@qq.com",
                    create_time: "2019-11-30",
                    ma_state: true,
                    role_name: "打工仔"
                  }
                ],
                total: 2
              });
              break;
            // eslint-disable-next-line no-duplicate-case
            case "3":
              res.json({
                userlist: [
                  {
                    id: 1,
                    username: "打工仔",
                    type: 1,
                    mobile: "15655117358",
                    email: "243651464@@qq.com",
                    create_time: "2019-11-30",
                    ma_state: true,
                    role_name: "超级管理员"
                  },
                  {
                    id: 1,
                    username: "打工仔",
                    type: 1,
                    mobile: "15655117358",
                    email: "243651464@@qq.com",
                    create_time: "2019-11-30",
                    ma_state: true,
                    role_name: "超级管理员"
                  },
                  {
                    id: 1,
                    username: "打工仔",
                    type: 1,
                    mobile: "15655117358",
                    email: "243651464@@qq.com",
                    create_time: "2019-11-30",
                    ma_state: true,
                    role_name: "打工仔"
                  }
                ],
                total: 3
              });
              break;
            // eslint-disable-next-line no-duplicate-case
            case "5":
              res.json({
                userlist: [
                  {
                    id: 1,
                    username: "打工仔",
                    type: 1,
                    mobile: "15655117358",
                    email: "243651464@@qq.com",
                    create_time: "2019-11-30",
                    ma_state: true,
                    role_name: "超级管理员"
                  },
                  {
                    id: 1,
                    username: "打工仔",
                    type: 1,
                    mobile: "15655117358",
                    email: "243651464@@qq.com",
                    create_time: "2019-11-30",
                    ma_state: true,
                    role_name: "超级管理员"
                  },
                  {
                    id: 1,
                    username: "打工仔",
                    type: 1,
                    mobile: "15655117358",
                    email: "243651464@@qq.com",
                    create_time: "2019-11-30",
                    ma_state: true,
                    role_name: "打工仔"
                  },
                  {
                    id: 1,
                    username: "打工仔",
                    type: 1,
                    mobile: "15655117358",
                    email: "243651464@@qq.com",
                    create_time: "2019-11-30",
                    ma_state: true,
                    role_name: "超级管理员"
                  },
                  {
                    id: 1,
                    username: "打工仔",
                    type: 1,
                    mobile: "15655117358",
                    email: "243651464@@qq.com",
                    create_time: "2019-11-30",
                    ma_state: true,
                    role_name: "打工仔"
                  }
                ],
                total: 5
              });
              break;
            // eslint-disable-next-line no-duplicate-case
            case "10":
              res.json({
                userlist: [
                  {
                    id: 1,
                    username: "打工仔",
                    type: 1,
                    mobile: "15655117358",
                    email: "243651464@@qq.com",
                    create_time: "2019-11-30",
                    ma_state: true,
                    role_name: "超级管理员"
                  },
                  {
                    id: 1,
                    username: "打工仔",
                    type: 1,
                    mobile: "15655117358",
                    email: "243651464@@qq.com",
                    create_time: "2019-11-30",
                    ma_state: true,
                    role_name: "超级管理员"
                  },
                  {
                    id: 1,
                    username: "打工仔",
                    type: 1,
                    mobile: "15655117358",
                    email: "243651464@@qq.com",
                    create_time: "2019-11-30",
                    ma_state: true,
                    role_name: "打工仔"
                  },
                  {
                    id: 1,
                    username: "打工仔",
                    type: 1,
                    mobile: "15655117358",
                    email: "243651464@@qq.com",
                    create_time: "2019-11-30",
                    ma_state: true,
                    role_name: "超级管理员"
                  },
                  {
                    id: 1,
                    username: "打工仔",
                    type: 1,
                    mobile: "15655117358",
                    email: "243651464@@qq.com",
                    create_time: "2019-11-30",
                    ma_state: true,
                    role_name: "打工仔"
                  },
                  {
                    id: 1,
                    username: "打工仔",
                    type: 1,
                    mobile: "15655117358",
                    email: "243651464@@qq.com",
                    create_time: "2019-11-30",
                    ma_state: true,
                    role_name: "超级管理员"
                  },
                  {
                    id: 1,
                    username: "打工仔",
                    type: 1,
                    mobile: "15655117358",
                    email: "243651464@@qq.com",
                    create_time: "2019-11-30",
                    ma_state: true,
                    role_name: "超级管理员"
                  },
                  {
                    id: 1,
                    username: "打工仔",
                    type: 1,
                    mobile: "15655117358",
                    email: "243651464@@qq.com",
                    create_time: "2019-11-30",
                    ma_state: true,
                    role_name: "打工仔"
                  },
                  {
                    id: 1,
                    username: "打工仔",
                    type: 1,
                    mobile: "15655117358",
                    email: "243651464@@qq.com",
                    create_time: "2019-11-30",
                    ma_state: true,
                    role_name: "超级管理员"
                  },
                  {
                    id: 1,
                    username: "打工仔",
                    type: 1,
                    mobile: "15655117358",
                    email: "243651464@@qq.com",
                    create_time: "2019-11-30",
                    ma_state: true,
                    role_name: "打工仔"
                  }
                ],
                total: 10
              });
              break;
          }
        });
        // -----------
      }
    }
  }
};
